﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using BCDto.Sim.StaffNotification;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.Sim.StaffNotification;

namespace BCTMSRESTful.Controllers.Management.StaffNotification
{
    /// <summary>
    /// 员工通知信息
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class StaffNotificationController : ManagementBaseController
    {
        private readonly IStaffNotificationService staffNotificationService;

        public StaffNotificationController(IStaffNotificationService staffNotificationService)
        {
            this.staffNotificationService = staffNotificationService;
        }

        #region 修改员工通知信息为已读
        /// <summary>
        ///  修改员工通知信息为已读
        /// </summary>
        /// <param name="staffNotificationId">员工通知信息Id</param>
        /// <response code="200">修改员工通知信息成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{staff_notification_id}")]
        [Log("修改员工通知信息为已读")]
        [ProducesResponseType(typeof(StaffNotificationDto), 200)]
        public IActionResult Put([FromRoute(Name = "staff_notification_id")]long staffNotificationId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.staffNotificationService.Update(staffNotificationId));
        }
        #endregion

        #region 删除员工通知信息
        /// <summary>
        ///  删除员工通知信息
        /// </summary>
        /// <param name="staffNotificationId">员工通知信息Id</param>
        /// <response code="204">删除员工通知信息成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{staff_notification_id}")]
        [Log("删除员工通知信息")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "staff_notification_id")]long staffNotificationId)
        {
            this.staffNotificationService.Delete(staffNotificationId);
            return StatusCode((int)HttpStatusCode.NoContent);
        }
        #endregion

        #region 获取员工未读消息数量
        /// <summary>
        ///  获取员工未读消息数量
        /// </summary>
        /// <response code="200">获取员工未读消息数量</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(int), 200)]
        public IActionResult Count()
        {
            return StatusCode((int)HttpStatusCode.OK, this.staffNotificationService.GetNoneReadCount(this.Admin));
        }
        #endregion

        #region 获取员工通知信息（分页）
        /// <summary>
        ///  获取员工通知信息（分页）
        /// </summary>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取员工通知信息（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<StaffNotificationDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "sort_name")]string sortName,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.staffNotificationService.Query(this.Admin, start, end, sortName, ascending, index, size));
        }
        #endregion
    }
}
